Imports MySql.Data.MySqlClient

Public Class Connection
    Dim transacao As MySqlTransaction
    Dim conexao As MySqlConnection
    Dim cmd As MySqlCommand = New MySqlCommand()

    Public Sub openconection()
        ' If conexao Is Nothing Or (conexao.State = ConnectionState.Broken) Or (conexao.State = ConnectionState.Closed) Then
        conexao = New MySqlConnection()
        conexao.ConnectionString = "Server=localhost;Database=manager_ticket;Uid=root;Pwd='';"
        conexao.Open()
        'End If
    End Sub

    Public Sub closeconection()
        If conexao.State = ConnectionState.Open Then
            conexao.Close()
            conexao.Dispose()
            conexao = Nothing
        End If
    End Sub
    Public Function executeds(ByVal sql As String) As DataSet
        Dim ds As New DataSet
        Dim da As MySqlDataAdapter = New MySqlDataAdapter()
        Try
            Me.openconection()

            cmd.CommandType = CommandType.Text
            cmd.CommandText = sql
            cmd.Connection = conexao

            da.SelectCommand = cmd
            da.Fill(ds)
            da.Dispose()
            Return ds

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return ds
    End Function
    Public Function insertdados(ByVal sql As String)
        Me.openconection()
        cmd.CommandType = CommandType.Text
        cmd.CommandText = sql
        cmd.Connection = conexao
        cmd.ExecuteNonQuery()
    End Function
    Public Function executecontacs(ByVal sql As String) As DataSet
        Dim ds As New DataSet
        Dim da As MySqlDataAdapter = New MySqlDataAdapter()
        Try
            Me.openconection()

            cmd.CommandType = CommandType.Text
            cmd.CommandText = sql
            cmd.Connection = conexao

            da.SelectCommand = cmd
            da.Fill(ds)
            da.Dispose()
            Return ds

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return ds
    End Function

End Class




'> Preencher combobox VB 2005

'sql = "SELECT * FROM servicedesk_ticket_status_types"
'       ds = conn.executeds(sql)
'      ComboBox7.DataSource = ds.Tables(0)
'    ComboBox7.DisplayMember = "name"

